package vip.xiaonuo.smzq.modular.lifecycle.service.factory.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.annotation.CommonWrapper;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclWjglb;
import vip.xiaonuo.smzq.modular.lifecycle.entity.PsbaGtWjglb;
import vip.xiaonuo.smzq.modular.lifecycle.service.entity.PsbaGtWjglbService;
import vip.xiaonuo.smzq.modular.lifecycle.service.factory.produce.WrapperMeter;
import vip.xiaonuo.smzq.modular.lifecycle.vo.QueryMineStoreVO;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <ul>
 * <li>name:  外部调用实现</li>
 * <li>author name: GEOSCENE_YUYANFEI</li>
 * <li>create time: 2024-03-20 15:31:25</li>
 * </ul>
 */
@Service(WrapperMeter.revRecWrapperMeterServiceName)
public class RevRecWrapperMeterImpl implements WrapperMeter {

    @Autowired
    PsbaGtWjglbService psbaGtWjglbService;

    @Qualifier(WrapperMeter.comWrapperMeterServiceName)
    @Autowired
    WrapperMeter comWrapperMeter;

    @Override
    public List<QueryMineStoreVO> wrapper(List<QueryMineStoreVO> allQueryMinStoreVOS) {
        List<QueryMineStoreVO> result = CollUtil.newArrayList();

        List<String> woFileIds = comWrapperMeter.getWithOutFileIds(allQueryMinStoreVOS);
        if(CollUtil.isEmpty(woFileIds)){
            return allQueryMinStoreVOS;
        }
//        过滤出(例如:评审备案的文件列表)
        List<PsbaGtWjglb> psbaGtWjglbs = psbaGtWjglbService.lambdaQuery().in(PsbaGtWjglb::getPkid, woFileIds).list();

        List<KclWjglb> kclWjglbs = comWrapperMeter.tranKWB(psbaGtWjglbs);

        Map<String,KclWjglb> kwbMap = kclWjglbs.stream().collect(Collectors.toMap(KclWjglb::getPkid, Function.identity()));
        return allQueryMinStoreVOS.stream().map(ele->{
            if(StrUtil.isNotBlank(ele.getFileId())){
                if(ObjectUtil.isNotEmpty(kwbMap.get(ele.getFileId()))){
                    ele.setKclWjglbList(CollUtil.newArrayList(kwbMap.get(ele.getFileId())));
                }
            }
            return ele;
        }).collect(Collectors.toList());
    }

    @Override
    public List<String> getWithOutFileIds(List<QueryMineStoreVO> allQueryMinStoreVOS) {
        return null;
    }

    @Override
    public <T> List<KclWjglb> tranKWB(List<T> list) {
        return null;
    }


}


